# -*- coding: utf-8 -*-

import logging
import traceback

from odoo_contrib import http as contrib_http

from ...adaptor.factory import WechatMPFactory

logger = logging.getLogger(__name__)


@contrib_http.route('/wechat/mp/menu')
class WechatMPMenu(contrib_http.Controller):
    @contrib_http.route(['/create', '/create/<site>'], methods=['POST'], auth='none', type='http', force_custom_json_handler=True)
    def create_menu(self, **kwargs):
        site = kwargs.get('site')
        mpapp = WechatMPFactory()[site]
        menu = {
            'button': [
                {
                    'type': 'view',
                    'name': '进入卖场',
                    'url': 'http://dsm.xxmq.top:28069/mp/page/index.html',
                },
                {
                    'name': '买家中心',
                    'sub_button': [
                        {
                            'type': 'view',
                            'name': '推荐好货',
                            'url': 'http://dsm.xxmq.top:28069/mp/page/index.html',
                        },
                    ],
                },
                {
                    'name': '卖家中心',
                    'sub_button': [
                        {
                            'type': 'view',
                            'name': '拍品管理',
                            'url': 'http://dsm.xxmq.top:28069/mp/page/index.html',
                        },
                    ],
                },
            ],
        }
        mpapp.create_menu(menu)
        return {
            'success': True,
            'error': None,
        }
